import matplotlib.pyplot as plt
import math


def draw_parallel_lines_and_angles(corresponding_angles, alternate_interior_angles):
    # 定义两条平行线及其交于第三条直线的位置
    x1 = -5
    y1 = 0
    x2 = 5
    y2 = 0
    x3 = 0
    y3 = 3

    fig, ax = plt.subplots(figsize=(6, 6))

    # 绘制两条平行线
    ax.plot([x1, x2], [y1, y1], 'k-', label='Parallel Line 1')
    ax.plot([x1, x2], [y3, y3], 'k--', label='Parallel Line 2')

    # 绘制与平行线相交的第三条直线
    ax.plot([x1, x3], [y1, y3], 'r-', label='Transversal')

    # 计算并标注角度
    for i in range(2):
        # 同位角标注
        angle_corresponding_rad = corresponding_angles[i]
        x4 = x3 + 1.5 * math.cos(angle_corresponding_rad)
        y4 = y3 + 1.5 * math.sin(angle_corresponding_rad)
        ax.plot([x3, x4], [y3, y4], 'b-')
        ax.annotate(f'{math.degrees(angle_corresponding_rad):.1f}°', xy=(x4, y4),
                    xytext=(x4 + 0.5, y4 + 0.5),
                    arrowprops=dict(facecolor='black', shrink=0.05))

        # 内错角标注
        angle_alternate_rad = alternate_interior_angles[i]
        x5 = x2 if i == 0 else x1
        y5 = y3 + 1.5 * math.sin(angle_alternate_rad)
        ax.plot([x5, x3], [y3, y5], 'g-')
        ax.annotate(f'{math.degrees(angle_alternate_rad):.1f}°', xy=(x3, y5),
                    xytext=(x3 + 0.5, y5 + 0.5),
                    arrowprops=dict(facecolor='black', shrink=0.05))

    # 添加图例和坐标轴标签
    ax.legend()
    ax.set_xlim([-6, 6])
    ax.set_ylim([-1, 6])
    ax.axis('off')

    # 显示图形
    plt.show()


# 示例数据：假设两组同位角和内错角都是相等的
corresponding_angles = [math.pi / 4, math.pi / 4]  # 同位角
alternate_interior_angles = [math.pi / 3, math.pi / 3]  # 内错角

draw_parallel_lines_and_angles(corresponding_angles, alternate_interior_angles)
